package com.ruoyi.web.controller.market.product;

import java.util.List;
import java.util.Map;

import com.ruoyi.web.wapper.ProductMemberUnionWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ProductMemberUnion;
import com.ruoyi.product.service.IProductMemberUnionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联登用户Controller
 * 
 * @author ruoyi
 * @date 2022-07-31
 */
@Controller
@RequestMapping("/product/union")
public class ProductMemberUnionController extends BaseController
{
    private String prefix = "product/union";

    @Autowired
    private IProductMemberUnionService productMemberUnionService;

    @RequiresPermissions("product:union:view")
    @GetMapping()
    public String union()
    {
        return prefix + "/union";
    }

    /**
     * 查询联登用户列表
     */
    @RequiresPermissions("product:union:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductMemberUnion productMemberUnion)
    {
        startPage();
        List<Map<String, Object>> mapList = productMemberUnionService.selectProductMemberUnionListMap(productMemberUnion);
        mapList = new ProductMemberUnionWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出联登用户列表
     */
    @RequiresPermissions("product:union:export")
    @Log(title = "联登用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductMemberUnion productMemberUnion)
    {
        List<ProductMemberUnion> list = productMemberUnionService.selectProductMemberUnionList(productMemberUnion);
        ExcelUtil<ProductMemberUnion> util = new ExcelUtil<ProductMemberUnion>(ProductMemberUnion.class);
        return util.exportExcel(list, "联登用户数据");
    }

    /**
     * 新增联登用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存联登用户
     */
    @RequiresPermissions("product:union:add")
    @Log(title = "联登用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductMemberUnion productMemberUnion)
    {
        return toAjax(productMemberUnionService.insertProductMemberUnion(productMemberUnion));
    }

    /**
     * 修改联登用户
     */
    @RequiresPermissions("product:union:edit")
    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId") Long productId, ModelMap mmap)
    {
        ProductMemberUnion productMemberUnion = productMemberUnionService.selectProductMemberUnionByProductId(productId);
        mmap.put("productMemberUnion", productMemberUnion);
        return prefix + "/edit";
    }

    /**
     * 修改保存联登用户
     */
    @RequiresPermissions("product:union:edit")
    @Log(title = "联登用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductMemberUnion productMemberUnion)
    {
        return toAjax(productMemberUnionService.updateProductMemberUnion(productMemberUnion));
    }

    /**
     * 删除联登用户
     */
    @RequiresPermissions("product:union:remove")
    @Log(title = "联登用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productMemberUnionService.deleteProductMemberUnionByProductIds(ids));
    }
}
